package com.bw.base.mvvm

import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

abstract class BaseViewActivity<VDB:ViewDataBinding>:AppCompatActivity() {
    private val type by lazy {
        //取出泛型参数列表
        (javaClass.genericSuperclass as ParameterizedType) .actualTypeArguments
    }
    protected val binding by lazy {
        var clazz=type[0] as Class<VDB>
        var method=clazz.getMethod("inflate",LayoutInflater::class.java)
        method.invoke(null,layoutInflater) as VDB
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        intitView()
        intitData()
    }

    abstract fun intitView()

    abstract fun intitData()
}